cmake_minimum_required(VERSION 3.5)
project(ipa_room_exploration)

# build with c++11
if (NOT CMAKE_CXX_STANDARD)
    set(CMAKE_CXX_STANDARD 14)
endif ()

if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
    add_compile_options(-Wall -Wextra -Wpedantic)
endif ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-pedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-sign-compare")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-but-set-variable")
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_action REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(visualization_msgs REQUIRED)
find_package(nav2_util REQUIRED)
find_package(nav2_costmap_2d REQUIRED)
find_package(nav2_core REQUIRED)
find_package(pluginlib REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(builtin_interfaces REQUIRED)
find_package(rclcpp_lifecycle REQUIRED)
find_package(nav2_msgs REQUIRED)
find_package(tf2_eigen REQUIRED)

find_package(cv_bridge REQUIRED)
find_package(ipa_building_msgs REQUIRED)
#find_package(ipa_building_navigation REQUIRED)
find_package(angles REQUIRED)
find_package(OpenCV REQUIRED)
find_package(Boost REQUIRED COMPONENTS system thread chrono)

set(ipa_building_navigation_INCLUDE_DIRS $ENV{HOME}/ros2_ws/install/ipa_building_navigation/include)
set(tsp_solvers_LIBRARIES $ENV{HOME}/ros2_ws/install/ipa_building_navigation/lib/libtsp_solvers.so)
set(ipa_building_navigation_LIBRARIES $ENV{HOME}/ros2_ws/install/ipa_building_navigation/lib/libipa_building_navigation.so)

# Coin-Or and Cbc, included as ubuntu system package, without Cmake-module so include pkg-config file
#	!!! Important note: the order of the libraries when linking your executable is important, if it is wrong you get undefined references !!!
find_package(PkgConfig REQUIRED)
pkg_check_modules(CoinUtils REQUIRED coinutils)# coinutils osi-clp clp osi cbc cgl
Message(STATUS "coinutils include dirs: " ${CoinUtils_INCLUDE_DIRS})
pkg_check_modules(Cbc-lib REQUIRED cbc)
Message(STATUS "cbc include dirs: " ${Cbc-lib_INCLUDE_DIRS})


set(dependencies
        nav2_util
        cv_bridge
        geometry_msgs
        ipa_building_msgs
        #        ipa_building_navigation
        rclcpp
        sensor_msgs
        visualization_msgs
        rclcpp_action
        std_msgs
        tf2
        angles
        nav_msgs
        nav2_costmap_2d
        nav2_core
        tf2_eigen
        )

include_directories(
        include
        common/include
        ros/include
        ${OpenCV_INCLUDE_DIRS}
        ${Boost_INCLUDE_DIRS}
        ${ipa_building_navigation_INCLUDE_DIRS}
        ${CoinUtils_INCLUDE_DIRS}
        ${Cbc-lib_INCLUDE_DIRS}
)

### package library
add_library(${PROJECT_NAME} SHARED
        common/src/grid_point_explorator.cpp
        common/src/boustrophedon_explorator.cpp
        common/src/neural_network_explorator.cpp
        common/src/convex_sensor_placement_explorator.cpp
        common/src/energy_functional_explorator.cpp
        common/src/flow_network_explorator.cpp
        common/src/room_rotator.cpp
        common/src/meanshift2d.cpp
        ros/src/fov_to_robot_mapper.cpp
        )
target_link_libraries(${PROJECT_NAME}
        ${OpenCV_LIBRARIES}
        ${Boost_LIBRARIES}
        ${CoinUtils_LIBRARIES}
        ${Cbc-lib_LIBRARIES}
        ${tsp_solvers_LIBRARIES}
        ${ipa_building_navigation_LIBRARIES}
        )
ament_target_dependencies(${PROJECT_NAME} ${dependencies})

add_library(libcoverage_check_server SHARED
        ros/src/coverage_check_server.cpp
        )
target_link_libraries(libcoverage_check_server
        ${OpenCV_LIBS}
        ${Boost_LIBRARIES}
        )
ament_target_dependencies(libcoverage_check_server ${dependencies})

# map_accessibility_analysis lib
add_library(libmap_accessibility_analysis SHARED
        common/src/map_accessibility_analysis.cpp
        )
target_link_libraries(libmap_accessibility_analysis
        ${Boost_LIBRARIES}
        ${OpenCV_LIBRARIES}
        )
ament_target_dependencies(libmap_accessibility_analysis ${dependencies})

### room exploration action server, note: order of linking the Coin-Or packages important
add_executable(room_exploration_server ros/src/room_exploration_action_server.cpp)
target_link_libraries(room_exploration_server
        ${PROJECT_NAME}
        ${OpenCV_LIBRARIES}
        ${Boost_LIBRARIES}
        ${tsp_solvers_LIBRARIES}
        ${ipa_building_navigation_LIBRARIES}
        libcoverage_check_server
        libmap_accessibility_analysis
        )
ament_target_dependencies(room_exploration_server ${dependencies})

### room exploration client
add_executable(room_exploration_client
        ros/src/room_exploration_action_client.cpp
        )
target_link_libraries(room_exploration_client
        ${OpenCV_LIBS}
        ${Boost_LIBRARIES}
        ${PROJECT_NAME}
        )
ament_target_dependencies(room_exploration_client ${dependencies})

### server for coverage checking
#add_executable(coverage_check_server
#        ros/src/coverage_check_server_main.cpp
#        )
#target_link_libraries(coverage_check_server
#        ${OpenCV_LIBS}
#        ${Boost_LIBRARIES}
#        libcoverage_check_server
#        )
#ament_target_dependencies(coverage_check_server ${dependencies})

### server for coverage monitoring
#add_executable(coverage_monitor_server
#        ros/src/coverage_monitor_server.cpp
#        )
#target_link_libraries(coverage_monitor_server
#        ${OpenCV_LIBS}
#        ${Boost_LIBRARIES}
#        libcoverage_check_server
#        )
#ament_target_dependencies(coverage_monitor_server ${dependencies})

### evaluation of room exploration algorithms
#add_executable(room_exploration_evaluation
#        ros/src/room_exploration_evaluation.cpp
#        ros/src/fov_to_robot_mapper.cpp
#        )
#target_link_libraries(room_exploration_evaluation
#        ${OpenCV_LIBS}
#        libcoverage_check_server
#        )
#ament_target_dependencies(room_exploration_evaluation ${dependencies})


# map_accessibility_analysis_server
#add_executable(map_accessibility_analysis_server
#        ros/src/map_accessibility_analysis_server.cpp
#        )
#target_link_libraries(map_accessibility_analysis_server
#        ${Boost_LIBRARIES}
#        ${OpenCV_LIBRARIES}
#        map_accessibility_analysis
#        )
#ament_target_dependencies(map_accessibility_analysis_server ${dependencies})

# map_accessibility_analysis_client
#add_executable(map_accessibility_analysis_client
#        ros/src/map_accessibility_analysis_client.cpp)
#target_link_libraries(map_accessibility_analysis_client
#        ${Boost_LIBRARIES}
#        ${OpenCV_LIBRARIES}
#        )
#ament_target_dependencies(map_accessibility_analysis_client ${dependencies})


#############
## Install ##
#############
# Mark executables and/or libraries for installation

install(TARGETS
        ${PROJECT_NAME}
        room_exploration_server
        room_exploration_client
        libcoverage_check_server
        libmap_accessibility_analysis
        ARCHIVE DESTINATION lib
        LIBRARY DESTINATION lib
        RUNTIME DESTINATION lib/${PROJECT_NAME}
        )
#uncomment this if you have a common-directory with header-files
install(DIRECTORY common/include/${PROJECT_NAME}/
        DESTINATION include/${PROJECT_NAME}/
        )

#uncomment this if you have header-files in your project
install(DIRECTORY ros/include/${PROJECT_NAME}/
        DESTINATION include/${PROJECT_NAME}/
        )

##uncomment this if you use launch and yaml files
install(DIRECTORY ros/launch
        DESTINATION share/${PROJECT_NAME}
        )
ament_package()

